package com.book.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil {

	public static Session getSession(){
		Session session = null;
		ServiceRegistry serviceRegistry = 
				new StandardServiceRegistryBuilder().configure().build();
		Configuration configuration = new Configuration();
		SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		session = sessionFactory.openSession();
		return session;
	}
	
	public static void closeAll(Session session){
		if(session != null){
			session.close();
		}
	}
	
}
